home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: 70253.3461@compuserve.com (Larry Widing)
- Newsgroups: comp.lang.c++
- Subject: Re: Mutually referring header files
- Date: Thu, 11 Apr 1996 17:32:42 GMT
- Organization: CompuServe Incorporated
- Message-ID: <316d40d9.13819600@news.compuserve.com>
- References: <4ked7q$8g3@dub-news-svc-1.compuserve.com>
- NNTP-Posting-Host: hd77-125.compuserve.com
- X-Newsreader: Forte Agent .99d/32.182
-
- RossBoylan@aol.com (Ross Boylan) wrote:
-
- >I have 2 classes A + B, defined in separate files. Each refers to and
- >messages the other. What is the best way to handle this?
-
- I would make the follwoing changes to your layout:
-
- >
- >1) My naive approach was
- >a.h----------------------------------------------------------
- >#ifndef ah
- >#define ah
- >#include "b.h:
- >class A {
- >public:
- > void hello();
- >private:
- > B *pB;
- >//etc
- >};
- #else
- class A;
- >#endif
- >
- >b.h------------------------------------------------------------
- >#ifndef bh
- >#define bh
- >#include "a.h"
- >class B{
- >public:
- > void hello();
- >private:
- > A *pA;
- >};
- #else
- class B;
- >#endif
-
- This will still keep the basic definitions of the class names, without
- duplicating the full declartions.
-
- Larry Widing
-